//
//  MyDynamicTableViewCell.m
//  Comma
//
//  Created by 杜远洋 on 15-1-16.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "MyDynamicTableViewCell.h"
#import "Masonry.h"
#import "GlobalMacro.h"
#define WS(weakSelf) __weak __typeof(&*self)weakSelf = self;
@implementation MyDynamicTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

        UIImageView *myPhoto = [UIImageView new];
        [self.contentView addSubview:myPhoto];
        [myPhoto setBackgroundColor:[UIColor grayColor]];
        self.myPhoto = myPhoto;
        
        
        UILabel *myCategory = [[UILabel alloc] init];
        [myCategory setTextColor:REDCOLOR];
        [myCategory setTextAlignment:NSTextAlignmentRight];
        [myCategory setFont:[UIFont systemFontOfSize:14]];
        [myCategory setBackgroundColor:[UIColor clearColor]];
        [self.contentView addSubview:myCategory];
        self.myCategory = myCategory;
        
        
        UILabel *myTitle = [UILabel new];
        [self.contentView addSubview:myTitle];

        [myTitle setTextColor:TEXTGREENCOLOR];
        [myTitle setTextAlignment:NSTextAlignmentLeft];
        [myTitle setFont:[UIFont systemFontOfSize:14]];
        [myTitle setBackgroundColor:[UIColor clearColor]];
        self.myTitle = myTitle;
       
        
        
        UILabel *myTime = [UILabel new];
        [self.contentView addSubview:myTime];
        [myTime setBackgroundColor:[UIColor clearColor]];
        [myTime setTextAlignment:NSTextAlignmentRight];
//        [myTime setText:@"3:28"];
        [myTime setFont:[UIFont systemFontOfSize:11]];
        [myTime setTextColor:TEXTERGRAY];
        self.myTime = myTime;
        
        UILabel *myBadge = [UILabel new];
        [myBadge setBackgroundColor:REDCOLOR];
        [myBadge setFont:[UIFont systemFontOfSize:14]];
        [myBadge setTextColor:[UIColor whiteColor]];
//        [myBadge setText:@"1"];
        [myBadge setTextAlignment:NSTextAlignmentCenter];
        myBadge.layer.cornerRadius = 7;
        myBadge.layer.masksToBounds = YES;
        [self.contentView addSubview:myBadge];
        self.myBadge = myBadge;

        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    WS(weakSelf);
    
    [self.myPhoto mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.mas_left).with.offset(8);
        make.top.equalTo(weakSelf.mas_top).with.offset(8);
        make.width.mas_equalTo(@(32));
        make.height.mas_equalTo(@(32));
    }];
    self.myPhoto.layer.cornerRadius = 16;
    self.myPhoto.layer.masksToBounds = YES;
    
    [self.myCategory setFrame:CGRectMake(40, 17, 45, 14)];
    
    
    [self.myTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.mas_top).with.offset(17);
        make.left.equalTo(_myPhoto.mas_right).with.offset(47);
        make.size.mas_equalTo(CGSizeMake(243, 14));

    }];
    
    
    
   
    
    UIFont *font = [UIFont fontWithName:@"HelveticaNeue" size:11];
    self.myTime.font = font;
    CGSize size = [self.myTime.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, nil]];
    CGFloat userTimeH = size.height;
    CGFloat userTimeW= size.width;
    [self.myTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(weakSelf.mas_bottom).with.offset(-8);
        make.right.mas_equalTo(-8);
        make.size.mas_equalTo(CGSizeMake(userTimeW * 3, userTimeH));
    }];

    [self.myBadge setFrame:CGRectMake(343 - (self.myBadge.text.length - 1) * 6 / 2 - 5, 17 , 14 + (self.myBadge.text.length - 1) * 6, 14)];

 
    
    
}
//#pragma mark - 设置小红圆的大小 根据数字位数
//- (CGRect)setMyBadgeFrame:(NSString *)number myLabel:(UILabel *)myLabel
//{
//    CGFloat width = myLabel.frame.size.width;
//    CGFloat height = myLabel.frame.size.height;
//    
//    return CGRectMake(myLabel.frame.origin.x , myLabel.frame.origin.y, width, height);
//    
//}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
